package com.work.daily.test;

import lombok.SneakyThrows;

import java.util.Base64;

/**
 * base64编码
 *
 * @author Shengkang.Mo
 * @create 2021-03-11 14:58
 */
public class Base64encode {

    @SneakyThrows
    public static void main(String[] args) {
        Base64.Decoder decoder = Base64.getDecoder();
        Base64.Encoder encoder = Base64.getEncoder();
        String text = "thirdusertest:ehsure@thirdusertest";

        byte[] textByte = text.getBytes("utf-8");
//dGhpcmR1c2VydGVzdD1laHN1cmVAdGhpcmR1c2VydGVzdA==
//dGhpcmR1c2VydGVzdDplaHN1cmVAdGhpcmR1c2VydGVzdA==
        //编码
        String encodedText = encoder.encodeToString(textByte);
        System.out.println(encodedText);

        //解码
        System.out.println(new String(decoder.decode(encodedText), "utf-8"));
    }
}
